package com.suxin.predicate.predicate;


import javax.validation.constraints.NotNull;
import java.util.function.Predicate;

/**
 * @author Tang
 * @classname DefaultPredicate
 * @description [  ]
 * @date 2022/11/2 09:21
 */
public class DefaultPredicate<T> implements Predicate<T> {

    private final Predicate<T> root;

    public DefaultPredicate(Predicate<T> root) {
        this.root = root;
    }

    @Override
    public boolean test(T t) {
        return this.root.test(t);
    }

    @NotNull
    public DefaultPredicate<T> andCondition(@NotNull Predicate<? super T> other) {
        return new DefaultPredicate<T>(and(other));
    }

    @NotNull
    public DefaultPredicate<T> negateCondition() {
        return new DefaultPredicate<T>(negate());
    }

    @NotNull
    public DefaultPredicate<T> orCondition(@NotNull Predicate<? super T> other) {
        return new DefaultPredicate<T>(or(other));
    }

    public Predicate<T> getRoot() {
        return root;
    }
}
